/**
 * @file
 * @auth jinguangguo
 * @date 2017/4/13
 */

import ajax from '../../grsc-base/util/ajax';
import filter from '../../grsc-base/util/filter';
import cookie from '../../grsc-base/util/cookie';
import baseService from '../../grsc-base/common/commonService';
import lib from './lib';

let commonService = $.extend({}, baseService, {

    // /**
    //  * 验证是否需要呈现图形验证码
    //  * @param param
    //  * @returns {*}
    //  */
    // needVerCode(param = {}) {
    //     return ajax.send('/exchangeApi/login/needVerCodeByEmail', {
    //         data: param
    //     });
    // },
    //
    // /**
    //  * 快速登录
    //  * @param param
    //  * @returns {*}
    //  */
    // quickLogin(param = {}) {
    //     return ajax.send('/exchangeApi/login/quickLoginByEmail', {
    //         data: param
    //     });
    // },

    /**
     * 添加和修改阿里支付
     * @param param
     * @param header
     * @returns {*}
     */
    updateAlipay(param = {}, header = {}){
        return ajax.post('/c2cApi/payconfig/c2calipay-config', {
            data: param,
            header: header
        });
    },

    /**
     * 添加和修改銀行支付
     * @param param
     * @param header
     * @returns {*}
     */
    updateBankPay(param = {}, header = {}){
        return ajax.post('/c2cApi/payconfig/c2cbank-config', {
            data: param,
            header: header
        });
    },

    /**
     *
     * 总资产数据
     * @param param
     * @returns {*}
     * */
    getTotalAssets(param = {},header) {
        return ajax.get('/exchangeApi/asset/accounts', {
            data: param,
            header:header
        });
    },

    /**
     * 普通登录
     * @param param
     * @param header
     * @returns {*}
     */
    login(param = {}, header) {
        return ajax.get('/exchangeApi/user/login', {
            data: param,
            header: header
        });
    },

    /**
     * 登出
     * @param param
     * @returns {*}
     */
    logout(param = {},header) {
        return ajax.get('/exchangeApi/user/logout', {
            data: param,
            header:header
        });
    },

    /**
     * 用户是否邮箱注册
     * @param param
     * @returns {*}
     */
    isUserEmailRegisted(param = {}) {
        return ajax.get('/exchangeApi/user/email-register-valid', {
            data: param
        });
    },

    /**
     * 站外发送邮箱验证码
     * @param param
     * @param header
     * @returns {*}
     */
    sendCode(param = {}, header = {}){
        return ajax.post('/exchangeApi/service/code', {
            data: param,
            header: header
        })
    },

    /**
     * 站内发送验证码
     * @param param
     * @returns {*}
     */
    sendCodeByLoginAfterByEmail(param = {}){
        return ajax.send('/exchangeApi/common/sendCodeByLoginAfterByEmail', {
            data: param
        })
    },

    /**
     * 获取个人基本信息
     * @param param
     * @returns {*}
     */
    basic(param = {}) {
        return ajax.get('/exchangeApi/user/basic', {
            data: param
        }).done(rep => {
            // 记录用户的姓名
            if (rep.code === window.CODE.SUCCESS) {
                window.app.user.requested = true;
                let user = rep.data;
                user.mobileText = '';//filter.phone(user.mobile);
                user.emailText = filter.email(user.account);
                window.app.user.value = user;

                if (rep.data.authLevel === 'LEVEL1') {   // 当有name属性时, 代表该用户已经实名
                    //cookie.set('HAS_AUTH', 1);
                    lib.setAuthLevel1(user.account);
                } else if(rep.data.authLevel === 'LEVEL2'){
                    lib.setAuthLevel2(user.account);
                } else {
                    lib.removeAuth(user.account);
                }
            }
        });
    },

    // /**
    //  * 是否实名——海外
    //  * @param param
    //  * @returns {*}
    //  */
    // getUserAuth(param = {}) {
    //     return ajax.send('/exchangeApi/user/getUserAuth', {
    //         data: param
    //     }).done(rep => {
    //         // 已经实名
    //         if (rep.code === window.CODE.SUCCESS) {
    //             cookie.set('HAS_AUTH', 1);
    //             window.localStorage.setItem('HAS_AUTH', 1);
    //         } else {
    //             cookie.remove('HAS_AUTH');
    //             window.localStorage.removeItem('HAS_AUTH');
    //         }
    //     })
    // },

    /**
     * OK Pay账户列表
     * @param param
     * @param header
     * @returns {*}
     * */
    getOkPayList(param = {}, header = {}) {
        param.channelType = 'OKPAY';
        return ajax.get('/exchangeApi/transfer/account/channel-account-list', {
            data: param,
            header: header
        });
    },

    /**
     * 获取用户认证信息
     * */
    getAuthenticationInfo(param = {}){
        return ajax.get('/exchangeApi/certification/overseas/authentication-info', {
            data: param
        })
    },


    /*
     * 每日提币限额
     * @param key : 'WITHDRAWLEVEL_0'/'WITHDRAWLEVEL_1'/'WITHDRAWLEVEL_2'
     * **/
    dailyWithdrawLimit(param = {}){
        return ajax.get('/exchangeApi/asset-config/asset-config-list',{
            data:param
        })
    },

    /*
     * 查询聚币用户信息记录
     * @param
     * **/
    queryJubiUserMsg(param = {}, header = {}){
        return ajax.post('/exchangeApi/user/jubi-query',{
            data:param,
            header: header
        })
    },

    /*
     * 聚币用户注册
     * @param
     * **/
    registerJubiUser(param = {}, header = {}){
        return ajax.post('/exchangeApi/user/jubi-register',{
            data:param,
            header: header
        })
    },



    /**
     * 查询用户谷歌验证码开关状态
     * 请求头：包含uid
     * 参数：无
     * 返回值：
     * isBound true/false
     * status ON/OFF
     * */
    googleCodeQuery(param = {}, header = {}) {
        return ajax.get('/exchangeApi/user/googlecode-query', {
            data: param,
            header: header
        });
    },

    /**
     *
     * */
    RegisterActive(param = {},header = {}){
        return ajax.get('/exchangeApi/user/email-activate',{
            data:param,
            header:header
        })
    },

    /**
     * 更新资产
     * */
    updateAccount(param = {}){
        return ajax.get('/exchangeApi/asset/update-user-account', {
            data: param
        });
    },

    /**
     * 设置手机号
     * */
    setPhone(param,header){
        // return ajax.sendOutside('/exchangeApi/user/cellphone-config',{

        return ajax.get('/exchangeApi/user/cellphone-config',{
            // type:'GET',
            data:param,
            header:header
        })
    },

    /**
     * 设置昵称
     * */
    setNickName(param){
        return ajax.get('/exchangeApi/user/nickname-config',{
            data:param
        })
    }


});

export default commonService;